<!--
 	* @author  wangjinqiu
-->
<template>
  <div id="hundredLearningSign-info">
    <div class="btn-container">
      <div class="btn-title">
        <span>打卡统计详情</span>
      </div>
      <div class="btn-btns">
        <el-button class="filter-item" type="primary" @click="handleFilter">{{ $t('table.search') }}</el-button>
        <el-button style="margin-left: 10px;" @click="$router.go(-1)">返回</el-button>
      </div>
    </div>
    <div style="font-size:15px;margin:-10px 0 10px 0">
      <span style="display:block;height:25px;line-height:25px;color:#606266">活动名称:{{ $route.query.title }}</span>
      <span style="display:block;height:25px;line-height:25px;color:#606266">用户名: {{ $route.query.realName }}</span>
    </div>
    <div class="table">
      <v-table
        v-if="tag"
        :list="list"
        :tag="tag"
        :list-loading="listLoading"
        :filter-column="filtercolumn"
        :selection="false"
        @handleSelectionChange="handleSelectionChange"
      >
        <!-- <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleDel(scope.row)">删除</el-button>
          </template>
        </el-table-column> -->
      </v-table>
    </div>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import { getStatisticsDetail } from '../api'
import { getToken } from '@/utils/auth'
import waves from '@/directive/waves' // Waves directive
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import VTable from '@/components/Table'
export default {
  name: 'PunchClockSignInfo',
  components: { Pagination, VTable },
  directives: { waves },
  data() {
    return {
      id: '',
      userId: '',
      searchshow: true,
      search: {
        realName: '',
        activityName: '',
        comName: '',
        time: ''
      },
      listQuery: {
        page: 1,
        limit: 10,
        userName: ''
      },
      list: [],
      total: 0,
      listLoading: false,
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7
        }
      },
      type: '',
      tag: ''
    }
  },
  created() {
    if (!this.$route.query.id) {
      this.$message({
        showClose: true,
        message: '参数异常！',
        type: 'warning',
        onClose: () => {
          this.$router.back()
        }
      })
    } else {
      this.id = this.$route.query.id
      this.type = this.$route.query.type
      this.tag = this.$route.query.type === 'CLOCK_ZYLX_CG' ? 'clockStatInfo-CG' : 'clockStatInfo'
      this.userId = this.$route.query.userId || ''
      this.getList()
    }
  },
  methods: {
    handleSelectionChange(arr) {},
    filtercolumn(scope, item) {
      if (item === 'passResult') {
        return scope.row[item] === 0 ? '未通过' : '通过'
      }
      return scope.row[item]
    },
    handleExport() {
      var searchText = ''
      var searchObj = {
        userName: this.listQuery.userName,
        realName: this.search.realName,
        comName: this.search.comName,
        activityName: this.search.activityName,
        token: getToken()
      }
      for (var i in searchObj) {
        if (searchObj[i]) {
          searchText += i + '=' + searchObj[i] + '&'
        }
      }
      searchText = searchText.slice(0, searchText.length - 1)
      window.open('/API-BACKEND/admin/asieGateRecord/export?' + searchText)
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resettingBtn() {
      this.listQuery.userName = ''
      for (const i in this.search) {
        this.search['' + i + ''] = ''
      }
      this.listQuery.page = 1
      this.getList()
    },
    /**
     * 格式化时间 传入s
     */
    formatterTime(str) {
      var h = Math.floor(str / 3600000)
      var m = Math.floor((str % 3600000) / 60000)
      var s = Math.floor((str % 60000) / 1000)
      var ms = Math.floor(str % 1000)
      return this.toDou(h) + ':' + this.toDou(m) + ':' + this.toDou(s) + ':' + this.toTwoDou(ms)
    },
    toDou(n) {
      if (n >= 10) {
        return '' + n
      } else {
        return '0' + n
      }
    },
    toTwoDou(n) {
      if (n < 10) {
        return '00' + n
      } else if (n >= 100) {
        return '' + n
      } else {
        return '0' + n
      }
    },
    getList(obj) {
      this.listLoading = true
      var query = {
        activityId: this.id,
        userId: this.userId,
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit
      }
      return new Promise((resolve, reject) => {
        getStatisticsDetail(query)
          .then((response) => {
            response.data.data.rows.forEach((item) => {
              if (item.costTime) {
                item.costTime = this.formatterTime(item.costTime)
              }
            })
            this.list = response.data.data.rows
            this.total = response.data.data.total
            this.listLoading = false
          })
          .catch((error) => {
            reject(error)
            this.listLoading = false
          })
      })
    },
    rowClass({ row, rowIndex }) {
      return {
        padding: '5px 0',
        height: '20px',
        background: 'rgba(247,247,248,1)'
      }
    }
  }
}
</script>

<!--<style lang="scss">-->
<style type="text/scss" lang="scss">
$dark_gray: #bfced6;
$mainColor: #18a5fd;
#hundredLearningSign-info {
  padding: 20px;

  .common-search {
    background-color: #fff;
    padding: 0 20px;
    .svg-container {
      padding: 0;
      color: $dark_gray;
      vertical-align: middle;
      display: inline-block;
      &_login {
        font-size: 20px;
      }
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .common-search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .common-search-more {
        font-size: 14px;
        font-weight: 500;
        color: $mainColor;
        cursor: pointer;
        margin-left: 10px;
      }
    }
    &.merge {
      height: 50px;
      line-height: 50px;
    }
    &.separate {
      .common-search-inner {
        padding-top: 10px;
        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }
          .el-input {
            position: relative;
            .el-input__inner {
              border: none;
              padding: 0;
            }
            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }
      .common-search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }
  .btn-container {
    display: flex;
    height: 36px;
    line-height: 36px;
    margin-top: 20px;
    margin-bottom: 20px;
    .btn-title {
      flex: 1;
      font-size: 16px;
      font-weight: bold;
      font-family: PingFangSC-Medium;
      color: rgba(51, 51, 51, 1);
    }
  }
  .dataForm::-webkit-scrollbar {
    display: none;
  }
}
</style>
